'use strict';

const Controller = require('egg').Controller;
class EditController extends Controller {
  async index() {
    const { ctx } = this;
    var {id,productNum,checked} = ctx.request.body
    if(checked != undefined && productNum != undefined){
      await this.ctx.model.User.updateOne({"cartList._id":id},{$set:{
        "cartList.$.productNum":productNum,
        "cartList.$.checked":checked
      }})
    }else if(checked != undefined && productNum == undefined){
      await this.ctx.model.User.updateOne({"cartList._id":id},{$set:{
        "cartList.$.checked":checked
      }})
    }else if(checked == undefined && productNum != undefined){
      await this.ctx.model.User.updateOne({"cartList._id":id},{$set:{
        "cartList.$.productNum":productNum
      }})
    }
    ctx.body={
      code:200,
      msg:'修改购物车成功'
    }
  }
}
module.exports = EditController;